extends layout
block content
  include navbar
  .layui-container.main
    .layui-row
      .layui-col-md8.layui-col-md-offset2
        canvas#tongji(width="100%",height="100%")
        .layui-form
          .layui-inline
            select#sorttongji(name="sort" lay-search lay-filter="sorttongji")
              option(value="") 排序
              option(value="hot") 热门排序
              option(value="nothot") 冷门排序
              option(value="newtime") 时间倒序
              option(value="oldtime") 时间正序
          .layui-inline
            select#tongjicounts(name="tongjicounts" lay-search lay-filter="tongjicounts")
              option(value="") 显示数量
              option(value="10") 10
              option(value="50") 50
              option(value="100") 100
          .layui-btn#submitsort 确定筛选
        table.layui-table
          thead
            tr
              th 电影名
              th 播放次数
              th 创建时间
              th 分享链接
          tbody
            each movie in movies
              tr
                td #{movie.originalname}
                td #{movie.count}
                th #{movie.formatdate}
                td
                  a(href="/share/#{movie._id}" target="_blank") 链接
        nav.pages
          if( pages> 1)
            ul.pagination
              != createPagination(pages, page)
  script(src="/javascripts/Chart.min.js")
  p(style="display:none")#data #{data}
  script.
    var data = document.getElementById("data").innerText;
    var ctx = document.getElementById("tongji");
    new Chart(ctx, {
      data: JSON.parse(data),
      type: 'polarArea'
    });
    var sort = getQueryVariable('sort');
    var select = document.getElementById("sorttongji");
    var counts = getQueryVariable("counts");
    var selectcounts = document.getElementById("tongjicounts");
    for(var i=0;i<select.length;i++){
      if(select[i].value==sort) {
        select[i].selected = true;
      }
    };
    for(var i=0;i<selectcounts.length;i++){
      if(selectcounts[i].value==counts) {
        selectcounts[i].selected = true;
      }
    };
    function getQueryVariable(variable)
    {
           var query = window.location.search.substring(1);
           var vars = query.split("&");
           for (var i=0;i<vars.length;i++) {
                   var pair = vars[i].split("=");
                   if(pair[0] == variable){return pair[1];}
           }
           return(false);
    }